package sg.edu.nus.comp.icreate.ivletalk;

import java.util.List;

import sg.edu.nus.comp.icreate.ivletalk.events.NewEventActivity;
import sg.edu.nus.comp.icreate.ivletalk.voice.VoiceCommand;
import android.content.Intent;
import android.view.Menu;
import android.view.MenuItem;

public abstract class EventBaseActivity extends BaseActivity {

	private static final int INDEX_MENU_ITEM_NEW_POST = 2;

	@Override
	public boolean onOptionsItemSelected(MenuItem item) {
		if (item.getItemId() == R.id.actionNewPost) {
			Intent intent = new Intent(this, NewEventActivity.class);
			startActivityForResult(intent, NewEventActivity.REQUEST_CODE_NEW_EVENT);
			return true;
		} else {
			return super.onOptionsItemSelected(item);
		}
	}

	@Override
	protected void onActivityResult(int requestCode, int resultCode, Intent data) {

		super.onActivityResult(requestCode, resultCode, data);

		if (requestCode == NewEventActivity.REQUEST_CODE_NEW_EVENT)
			handleActionRefresh();
	}

	@Override
	public boolean onCreateOptionsMenu(Menu menu) {
		super.onCreateOptionsMenu(menu);
		MenuItem menuItem = menu.getItem(INDEX_MENU_ITEM_NEW_POST);
		menuItem.setVisible(true);
		return true;
	}

	@Override
	public boolean executeMenuVoiceCommand(String cmd) {
		super.executeMenuVoiceCommand(cmd);
		if (cmd.equals(VoiceCommand.NEW.getPattern())) {
			return goNewPost();
		}
		return false;

	}

	protected void goToItem(int position) {
		// do nothing
	}

	protected List<?> getDisplayedItemList() {
		// do nothing
		return null;
	}
}
